﻿using System;
namespace Producers.Kis.Xtee.Riik.Ee.Producer.Kis {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="Address", Namespace="http://producers.kis.xtee.riik.ee/producer/kis", Target=typeof(Address))]
    public class AddressSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IAddress clazz;
        
        public AddressSerializer(IAddress clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("AddressType");
            if (clazz.AddressType!=null) {
                Writer.WriteTypeAttribute("http://producers.kis.xtee.riik.ee/producer/kis", "AddressType");
                Writer.WriteString(clazz.AddressType.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : AddressType");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("Choice");
            if (clazz.Choice!=null) {
                Writer.WriteTypeAttribute("http://producers.kis.xtee.riik.ee/producer/kis", "CountryChoice");
                Writer.WriteString(clazz.Choice.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Choice");
            }
            Writer.WriteEndElement();
            if (clazz.Country!=null) {
                Writer.WriteStartElement("Country");
                Writer.WriteTypeAttribute("http://producers.kis.xtee.riik.ee/producer/kis", "NonEmptyString");
                Writer.WriteString(clazz.Country.ToString());
                Writer.WriteEndElement();
            }
            if (clazz.County!=null) {
                Writer.WriteStartElement("County");
                Writer.WriteTypeAttribute("http://producers.kis.xtee.riik.ee/producer/kis", "NonEmptyString");
                Writer.WriteString(clazz.County.ToString());
                Writer.WriteEndElement();
            }
            if (clazz.RuralMunicipalityCity!=null) {
                Writer.WriteStartElement("RuralMunicipalityCity");
                Writer.WriteTypeAttribute("http://producers.kis.xtee.riik.ee/producer/kis", "NonEmptyString");
                Writer.WriteString(clazz.RuralMunicipalityCity.ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Settlement!=null) {
                Writer.WriteStartElement("Settlement");
                Writer.WriteTypeAttribute("http://producers.kis.xtee.riik.ee/producer/kis", "NonEmptyString");
                Writer.WriteString(clazz.Settlement.ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Street!=null) {
                Writer.WriteStartElement("Street");
                Writer.WriteTypeAttribute("http://producers.kis.xtee.riik.ee/producer/kis", "NonEmptyString");
                Writer.WriteString(clazz.Street.ToString());
                Writer.WriteEndElement();
            }
            if (clazz.House!=null) {
                Writer.WriteStartElement("House");
                Writer.WriteTypeAttribute("http://producers.kis.xtee.riik.ee/producer/kis", "NonEmptyString");
                Writer.WriteString(clazz.House.ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Apartment!=null) {
                Writer.WriteStartElement("Apartment");
                Writer.WriteTypeAttribute("http://producers.kis.xtee.riik.ee/producer/kis", "NonEmptyString");
                Writer.WriteString(clazz.Apartment.ToString());
                Writer.WriteEndElement();
            }
            if (clazz.PostalCode!=null) {
                Writer.WriteStartElement("PostalCode");
                Writer.WriteTypeAttribute("http://producers.kis.xtee.riik.ee/producer/kis", "NonEmptyString");
                Writer.WriteString(clazz.PostalCode.ToString());
                Writer.WriteEndElement();
            }
            Writer.WriteStartElement("Correspondence");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "boolean");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdBoolean(((bool)(clazz.Correspondence))).ToString());
            Writer.WriteEndElement();
            if (clazz.OtherFormat!=null) {
                Writer.WriteStartElement("OtherFormat");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.OtherFormat))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.LandRegistryCode!=null) {
                Writer.WriteStartElement("LandRegistryCode");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.LandRegistryCode))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.CompanyName!=null) {
                Writer.WriteStartElement("CompanyName");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.CompanyName))).ToString());
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="AddressType") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Address>AddressType");
                }
                clazz.AddressType = new global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.AddressType(Reader.ReadElementString("AddressType"));
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>Address>AddressType", Reader.LocalName);
            }
            if (Reader.LocalName=="Choice") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Address>Choice");
                }
                clazz.Choice = new global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.CountryChoice(Reader.ReadElementString("Choice"));
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>Address>Choice", Reader.LocalName);
            }
            if (Reader.LocalName=="Country") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Address>Country");
                }
                clazz.Country = new global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.NonEmptyString(Reader.ReadElementString("Country"));
            }
            if (Reader.LocalName=="County") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Address>County");
                }
                clazz.County = new global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.NonEmptyString(Reader.ReadElementString("County"));
            }
            if (Reader.LocalName=="RuralMunicipalityCity") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Address>RuralMunicipalityCity");
                }
                clazz.RuralMunicipalityCity = new global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.NonEmptyString(Reader.ReadElementString("RuralMunicipalityCity"));
            }
            if (Reader.LocalName=="Settlement") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Address>Settlement");
                }
                clazz.Settlement = new global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.NonEmptyString(Reader.ReadElementString("Settlement"));
            }
            if (Reader.LocalName=="Street") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Address>Street");
                }
                clazz.Street = new global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.NonEmptyString(Reader.ReadElementString("Street"));
            }
            if (Reader.LocalName=="House") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Address>House");
                }
                clazz.House = new global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.NonEmptyString(Reader.ReadElementString("House"));
            }
            if (Reader.LocalName=="Apartment") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Address>Apartment");
                }
                clazz.Apartment = new global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.NonEmptyString(Reader.ReadElementString("Apartment"));
            }
            if (Reader.LocalName=="PostalCode") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Address>PostalCode");
                }
                clazz.PostalCode = new global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.NonEmptyString(Reader.ReadElementString("PostalCode"));
            }
            if (Reader.LocalName=="Correspondence") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Address>Correspondence");
                }
                clazz.Correspondence = new global::Xtee.Core.Schema.XsdBoolean(Reader.ReadElementString("Correspondence")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>Address>Correspondence", Reader.LocalName);
            }
            if (Reader.LocalName=="OtherFormat") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Address>OtherFormat");
                }
                clazz.OtherFormat = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("OtherFormat")).Value;
            }
            if (Reader.LocalName=="LandRegistryCode") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Address>LandRegistryCode");
                }
                clazz.LandRegistryCode = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("LandRegistryCode")).Value;
            }
            if (Reader.LocalName=="CompanyName") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Address>CompanyName");
                }
                clazz.CompanyName = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("CompanyName")).Value;
            }
        }
    }
}
